<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title></title>
    <script src="../js/mui.min.js"></script>
    <link href="../css/mui.min.css" rel="stylesheet"/>
    <link href="../style/fjol_style.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="../style/xol_style.css"/>
    <link href="../css/iosSelect.css" rel="stylesheet" />
    <link href="../css/mui.picker.min.css" rel="stylesheet" />
    
    <script type="text/javascript" charset="utf-8">
      	mui.init();
    	
   		
    </script>
	</head>
	<style>
		.mui-input-row label~input, .mui-input-row label~select, .mui-input-row label~textarea{
			margin-right: 10px;
			width: 50%;
		}
		.mui-input-row .mui-input-clear~.mui-icon-clear, .mui-input-row .mui-input-password~.mui-icon-eye, .mui-input-row .mui-input-speech~.mui-icon-speech{
			width: 30px;
		}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav newbgRed">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title"></h1>
		</header>
		<div class="mui-content">
		    <div class="mui-scroll-wrapper" style="bottom: 40px; top: 55px; background: #F5F7F7;">
		        <div class="mui-scroll">
		            <!--这里放置真实显示的DOM内容-->
		            <div class="mui-input-group">
					    <div class="mui-input-row">
					        <label>姓名</label>
					        <input type="text" id="realname" class="mui-input-clear mui-text-right" value="" placeholder="怎么称呼您？">
					    </div>
					    <div class="mui-input-row">
					        <label>手机号</label>
					        <input type="number" id="mobile" class="mui-input-clear mui-text-right" value="" placeholder="必填">
					    </div>
					</div>
		            
		            <div class="mui-input-group mt10">
		            	<!--<div class="mui-table-view-cell mui-input-row">
	                        <a class="mui-navigate-right" id="searchBuilding">
	                     楼盘
	                    		<span class="mui-pull-right mr10"></span>
	                		</a>
	                    </div>
		            	<div class="mui-input-row">
					        <label>地址</label>
					        <input type="text" id="addrValue" class="mui-input-clear mui-text-right" placeholder="" value="">
					    </div>
		            	<div class="mui-input-row">
					        <label>楼栋号</label>
					        <input type="text" id="buildNumber" class="mui-input-clear mui-text-right" placeholder="必填" value="">
					    </div>
					    <div class="mui-input-row">
					        <label>门牌号</label>
					        <input type="text" id="houseNumber" class="mui-input-clear mui-text-right" placeholder="必填" value="">
					    </div>-->
					    <div class="mui-input-row" id="buildTypeDiv">
					        <label>房屋类型</label>
					        <input type="text" readonly id="buildType" class="mui-input-clear mui-text-right" value="">
					    </div>
					    <div class="mui-input-row" id="workDecorationPlaceDiv">
					        <label>场地类型</label>
					        <input type="text" readonly id="workDecorationPlace" class="mui-input-clear mui-text-right" value="">
					    </div>
					    <div class="mui-input-row" id="decorationTypeDiv">
					        <label>装修标准</label>
					        <input type="text" readonly id="decorationType" class="mui-input-clear mui-text-right" value="">
					    </div>
					    <div class="mui-input-row" id="houseType">
					        <label>户型</label>
					        <input type="text" readonly class="mui-text-right" placeholder="" value="1室0厅0卫">
					    </div>
					    <div class="mui-input-row">
					        <label>面积</label>
					        <span class="mui-pull-right pr10 mt10">平方</span>
					        <input type="number" id="square" class="mui-input-clear mui-text-right mui-pull-right" style="width: 48%;" placeholder="" value="">
					    </div>
					    <div class="mui-input-row" id="budgetDiv">
					        <label>装修预算</label>
					        <span class="mui-pull-right pr10 mt10 newRed">元</span>
					        <input type="number" id="budget" class="mui-input-clear mui-text-right mui-pull-right" style="width: 48%;" placeholder="" value="">
					    </div>
					   <!--<div class="mui-input-row">
					        <label>房屋类型</label>
					        <input type="text" readonly id="buildType" class="mui-input-clear mui-text-right" value="">
					    </div>-->
					</div>
					<div class="mui-input-group mt10" id="housekeepingTypeDiv">
						<div class="mui-input-row">
					        <label>服务类型</label>
					        <input type="text" id="housekeepingType" class="mui-input-clear mui-text-right mui-pull-right" placeholder="" value="">
					    </div>
                   </div>
		        </div>
		    </div>
		    <nav class="mui-bar mui-bar-tab" style="background: none; box-shadow: none;">
		    	<button type="button" class="mui-btn mui-btn-blue colorWhite mui-btn-block pct80 mauto borderRadius6" id="submitIssue">确认发布</button>
		    </nav>
		</div>
		<script src="../js/md5.js"></script>
		<script src="../js/common.util.js"></script>
		<script src="../js/network.js"></script>
		<script src="../js/enum.util.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/mui.poppicker.js"></script>
		<script src="../css/iosSelect.js"></script>
		<script src="../js/xzx.open.js"></script>
		<script>
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		});
		
//		var buildingId= -1;
//		var buildingName='';
//		
//		document.querySelector('#searchBuilding').addEventListener('tap',function(){
//			openFileWindowWithPage('../selle_house','search_building',{
//				parentId:'company_appraisal'
//			});
//			
//		});
//		//楼盘名称
//		document.addEventListener('getBuilding',function(event){
//			buildingId = event.detail.buildingId;
//			buildingName = event.detail.buildingName;
////			console.log(buildingId);
//			document.querySelector('#searchBuilding span').innerHTML = buildingName;
//		});
		var type=1,shopId=1;
		var _url = '';
			
		mui.plusReady(function(){
			var wv = plus.webview.currentWebview();
			type = wv.type;		//1工装；2家装；3家政；4美食；5美食；6有钱
			shopId = wv.shopId;
//			console.log(shopId);
			switch(type){
				case 1:
					document.querySelector('.mui-title').innerHTML = '工装预约';
					document.querySelector('#workDecorationPlaceDiv').classList.remove('mui-hidden');	//场地类型-显示
					document.querySelector('#decorationTypeDiv').classList.remove('mui-hidden');	//装修标准-显示
					document.querySelector('#buildTypeDiv').classList.add('mui-hidden');	//房屋类型-隐藏
					document.querySelector('#housekeepingTypeDiv').classList.add('mui-hidden');	//服务类型-隐藏
					document.querySelector('#houseType').classList.add('mui-hidden');			//户型隐藏
					
					break;
				case 2:
					document.querySelector('.mui-title').innerHTML = '家装预约';
					document.querySelector('#workDecorationPlaceDiv').classList.add('mui-hidden');	//场地类型-隐藏
					document.querySelector('#decorationTypeDiv').classList.remove('mui-hidden');	//装修标准-显示
					document.querySelector('#buildTypeDiv').classList.remove('mui-hidden');	//房屋类型-显示
					document.querySelector('#housekeepingTypeDiv').classList.add('mui-hidden');	//服务类型-隐藏
					document.querySelector('#houseType').classList.add('mui-hidden');			//户型隐藏
					
					break;
				case 3:
					document.querySelector('.mui-title').innerHTML = '家政服务预约';
					document.querySelector('#workDecorationPlaceDiv').classList.add('mui-hidden');	//场地类型-隐藏
					document.querySelector('#decorationTypeDiv').classList.add('mui-hidden');	//装修标准-隐藏
					document.querySelector('#buildTypeDiv').classList.remove('mui-hidden');	//房屋类型-显示
					document.querySelector('#housekeepingTypeDiv').classList.remove('mui-hidden');	//服务类型-显示
					document.querySelector('#budgetDiv').classList.add('mui-hidden');		//装修预算-隐藏
					
					break;
				default:
					break;
			}
			var userInfo = common.myStorage.getItem('userInfo');
			if(userInfo){
				document.querySelector('#realname').value = userInfo.realname;
				document.querySelector('#mobile').value = userInfo.mobile;
			}
			//户型
			
			var bedRoomNumber=1,livingRoomNumber=0,toiletNumber=0;
			var houseType = document.querySelector('#houseType');//户型
			
			var bedRoomData = [{
				'id':'1',
				'value':'1室'
			}];
			var livingRoomData = [{
				'id':'0',
				'value':'厅'
			}];
			var toiletRoomData = [{
				'id':'0',
				'value':'卫'
			}];
			for (var i=0; i<10; i++) {
				bedRoomData[i]={
					'id':i+1,
					'value':i+1+'室'
				};
				if(i==9){
					bedRoomData[i]={
						'id':i+1,
						'value':'10室及以上'
					}
				}
			}
			for (var i=0; i<=10; i++) {
				livingRoomData[i]={
					'id':i,
					'value':i+'厅'
				};
				if(i==10){
					livingRoomData[i]={
						'id':i,
						'value':'10厅及以上'
					}
				}
				toiletRoomData[i]={
					'id':i,
					'value':i+'卫'
				};
				if(i==10){
					toiletRoomData[i]={
						'id':i,
						'value':'10卫及以上'
					}
				}
			}
			
			houseType.addEventListener('tap', function () {
				
		    var sanguoSelect = new IosSelect(3, 
		        [bedRoomData,livingRoomData, toiletRoomData],
		        {
		            title: '选择户型',
		            itemHeight: 35,
		            callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
		                bedRoomNumber = selectOneObj.value;
		                livingRoomNumber = selectTwoObj.value;
		                toiletNumber = selectThreeObj.value;
		                document.querySelector('#houseType input').value = selectOneObj.value+selectTwoObj.value+selectThreeObj.value;
		            }
				});
			});
			
			//房屋类型
			var _houseType = {
				name:'普通住宅',
				value:1
			}
			var enumHousTypeArray = enumUtils.getEnumDataByType('houseType');
			document.querySelector('#buildType').value = enumHousTypeArray[0].name;
			document.querySelector('#buildType').addEventListener('tap', function() {
				
//				console.log(JSON.stringify(enumHousTypeArray));
				var houseTypeArray = new Array();
				for(i in enumHousTypeArray) {
					houseTypeArray[i] = {
						text: enumHousTypeArray[i].name,
						value: enumHousTypeArray[i].value
					}
				}
				var houseTypePicker = new mui.PopPicker();
				houseTypePicker.setData(houseTypeArray);
				houseTypePicker.pickers[0].setSelectedIndex(_houseType.value - 1);
				houseTypePicker.show(function(SelectedItem) {
					_houseType.name = SelectedItem[0].text;
					_houseType.value = SelectedItem[0].value;
					document.querySelector('#buildType').value = SelectedItem[0].text;
				});
			});
			
			//装修标准
			var _decorationType = {
				name:'精装修',
				value:1
			}
			var enumdecorationTypeArray = enumUtils.getEnumDataByType('decorationType');	//工装-场地类型
			document.querySelector('#decorationType').value = enumdecorationTypeArray[0].name;
			document.querySelector('#decorationType').addEventListener('tap', function() {
				
//				console.log(JSON.stringify(enumdecorationTypeArray));
				var houseTypeArray = new Array();
				for(i in enumdecorationTypeArray) {
					houseTypeArray[i] = {
						text: enumdecorationTypeArray[i].name,
						value: enumdecorationTypeArray[i].value
					}
				}
				var houseTypePicker = new mui.PopPicker();
				houseTypePicker.setData(houseTypeArray);
				houseTypePicker.pickers[0].setSelectedIndex(_decorationType.value - 1);
				houseTypePicker.show(function(SelectedItem) {
					_decorationType.name = SelectedItem[0].text;
					_decorationType.value = SelectedItem[0].value;
					document.querySelector('#decorationType').value = SelectedItem[0].text;
				});
			});
			
			//场地类型
			var _workDecorationPlace = {
				name:'店铺',
				value:1
			}
			var enumWorkDecorationPlaceArray = enumUtils.getEnumDataByType('workDecorationPlace');	//工装-场地类型
			document.querySelector('#workDecorationPlace').value = enumWorkDecorationPlaceArray[0].name;
			document.querySelector('#workDecorationPlace').addEventListener('tap', function() {
				
//				console.log(JSON.stringify(enumWorkDecorationPlaceArray));
				var houseTypeArray = new Array();
				for(i in enumWorkDecorationPlaceArray) {
					houseTypeArray[i] = {
						text: enumWorkDecorationPlaceArray[i].name,
						value: enumWorkDecorationPlaceArray[i].value
					}
				}
				var houseTypePicker = new mui.PopPicker();
				houseTypePicker.setData(houseTypeArray);
				houseTypePicker.pickers[0].setSelectedIndex(_workDecorationPlace.value - 1);
				houseTypePicker.show(function(SelectedItem) {
					_workDecorationPlace.name = SelectedItem[0].text;
					_workDecorationPlace.value = SelectedItem[0].value;
					document.querySelector('#workDecorationPlace').value = SelectedItem[0].text;
				});
			});
			
			//服务类型
			var _housekeepingType = {
				name:'一般服务',
				value:1
			}
			var enumhousekeepingTypeArray = enumUtils.getEnumDataByType('housekeepingType');	//工装-场地类型
			document.querySelector('#housekeepingType').value = enumhousekeepingTypeArray[0].name;
			
			document.querySelector('#housekeepingType').addEventListener('tap', function() {
				
//				console.log(JSON.stringify(enumhousekeepingTypeArray));
				var houseTypeArray = new Array();
				for(i in enumhousekeepingTypeArray) {
					houseTypeArray[i] = {
						text: enumhousekeepingTypeArray[i].name,
						value: enumhousekeepingTypeArray[i].value
					}
				}
				var houseTypePicker = new mui.PopPicker();
				houseTypePicker.setData(houseTypeArray);
				houseTypePicker.pickers[0].setSelectedIndex(_housekeepingType.value - 1);
				houseTypePicker.show(function(SelectedItem) {
					_housekeepingType.name = SelectedItem[0].text;
					_housekeepingType.value = SelectedItem[0].value;
					document.querySelector('#housekeepingType').value = SelectedItem[0].text;
				});
			});
			
			
			//提交
			document.querySelector('#submitIssue').addEventListener('tap',function(){
				var square = parseFloat(document.querySelector('#square').value);//面积
//				var houseNumber = document.querySelector('#houseNumber').value;//门牌号
//				var buildNumber = document.querySelector('#buildNumber').value;//楼号

				var realname = document.querySelector('#realname').value;//姓名
				var mobile = document.querySelector('#mobile').value;//手机号
				
				var budget = parseFloat(document.querySelector('#budget').value);	//装修预算
				var param;
				console.log(budget);
				if(!square){
					square=0;
				}
				if(!budget){
					budget=0;
				}
				
				if(realname==''){
					mui.alert('请留下您的真实姓名，以便我们称呼您');
					return false;
				}
				if(mobile==''){
					mui.alert('请留下您的手机号，以便我们联系您');
					return false;
				}else if(!(/^1\d{10}$/.test(mobile))){
						mui.alert('请填写正确的手机号，以便我们联系您');
						return false;
				}
				if(type==1){		//工装
//				console.log('工装');
					param = [
				{
					key:'shopId',				//商家id
					value:shopId
				},{
					key:'realname',
					value:realname
				},{
					key:'mobile',
					value:mobile
				},{
					key:'square',		//面积
					value:square
				},{
					key:'budget',		//预算
					value:budget
				},{
					key:'decorationPlaceEnumValue',	//场地类型枚举值
					value:_workDecorationPlace.value
				},{
					key:'decorationPlaceName',		//场地类型名称
					value:_workDecorationPlace.name
				},{
					key:'decorationTypeEnumValue',	//装修类型名称
					value:_decorationType.value
				},{
					key:'decorationTypeName',	//装修类型名称
					value:_decorationType.name
				}];
				
				_url = 'work/decoration/add.json';
				}else if(type==2){		//家装
//				console.log('家装');
					param = [{
					key:'houseTypeEnumValue',	//房屋类型枚举值
					value:_houseType.value
				},{
					key:'houseTypeName',		//房屋类型名称
					value:_houseType.name
				},{
					key:'decorationTypeEnumValue',	//装修类型枚举值
					value:_decorationType.value
				},{
					key:'decorationTypeName',			//装修类型名称
					value:_decorationType.name
				},{
					key:'shopId',				//商家id
					value:shopId
				},{
					key:'realname',
					value:realname
				},{
					key:'mobile',
					value:mobile
				},{
					key:'square',		//面积
					value:square
				},{
					key:'budget',		//预算
					value:budget
				}];
				_url = 'house/decoration/add.json';
				}else if(type==3){		//家政
//				console.log('家政');
					param = [{
					key:'houseTypeEnumValue',	//房屋类型枚举值
					value:_houseType.value
				},{
					key:'houseTypeName',		//房屋类型名称
					value:_houseType.name
				},{
					key:'housekeepingTypeEnumValue',	//服务类型枚举值
					value:_housekeepingType.value
				},{
					key:'housekeepingTypeName',			//服务类型名称
					value:_housekeepingType.name
				},{
					key:'shopId',				//商家id
					value:shopId
				},{
					key:'realname',
					value:realname
				},{
					key:'mobile',
					value:mobile
				},{
					key:'square',		//面积
					value:square
				},{
					key:'bedRoomNumber',		//卧室数
					value:bedRoomNumber
				},{
					key:'livingRoomNumber',		//客厅数
					value:livingRoomNumber
				},{
					key:'toiletNumber',		//卫生间数
					value:toiletNumber
				}];
				_url = 'housekeeping/add.json';
			}
				fjNetwork.post(_url,param,function(data){
//					console.log(_url);
					mui.toast('您的房源数据已经提交，我们将第一时间与您联系，请耐心等待');
					setTimeout(function(){
						mui.back();
					},1500);
				},function(msg){
//					console.log(msg);
					mui.toast(msg);
				});
				
//					fjNetwork.post(_url,param,function(data){
//						console.log(_url);
////						mui.toast('您的房源数据已经提交，我们将第一时间与您联系，请耐心等待');
////						setTimeout(function(){
////							mui.back();
////						},1500);
//					},function(msg){
////						console.log(msg);
//						mui.toast(msg);
//					});
				
			});
		
		});
		</script>
	</body>
</html>
